package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AdPerformance;
import com.ruoyi.system.service.IAdPerformanceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 广告数据Controller
 * 
 * @author ruoyi
 * @date 2024-08-15
 */
@RestController
@RequestMapping("/system/performance")
public class AdPerformanceController extends BaseController
{
    @Autowired
    private IAdPerformanceService adPerformanceService;

    /**
     * 查询广告数据列表
     */
    @PreAuthorize("@ss.hasPermi('system:performance:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdPerformance adPerformance)
    {
        startPage();
        List<AdPerformance> list = adPerformanceService.selectAdPerformanceList(adPerformance);
        return getDataTable(list);
    }

    /**
     * 导出广告数据列表
     */
    @PreAuthorize("@ss.hasPermi('system:performance:export')")
    @Log(title = "广告数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AdPerformance adPerformance)
    {
        List<AdPerformance> list = adPerformanceService.selectAdPerformanceList(adPerformance);
        ExcelUtil<AdPerformance> util = new ExcelUtil<AdPerformance>(AdPerformance.class);
        util.exportExcel(response, list, "广告数据数据");
    }

    /**
     * 获取广告数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:performance:query')")
    @GetMapping(value = "/{performanceId}")
    public AjaxResult getInfo(@PathVariable("performanceId") Long performanceId)
    {
        return success(adPerformanceService.selectAdPerformanceByPerformanceId(performanceId));
    }

    /**
     * 新增广告数据
     */
    @PreAuthorize("@ss.hasPermi('system:performance:add')")
    @Log(title = "广告数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdPerformance adPerformance)
    {
        return toAjax(adPerformanceService.insertAdPerformance(adPerformance));
    }

    /**
     * 修改广告数据
     */
    @PreAuthorize("@ss.hasPermi('system:performance:edit')")
    @Log(title = "广告数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdPerformance adPerformance)
    {
        return toAjax(adPerformanceService.updateAdPerformance(adPerformance));
    }

    /**
     * 删除广告数据
     */
    @PreAuthorize("@ss.hasPermi('system:performance:remove')")
    @Log(title = "广告数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{performanceIds}")
    public AjaxResult remove(@PathVariable Long[] performanceIds)
    {
        return toAjax(adPerformanceService.deleteAdPerformanceByPerformanceIds(performanceIds));
    }
}
